<?php
/**
 * Created by PhpStorm.
 * User: gyq
 * Date: 2018/11/3
 * Time: 19:04
 */

namespace app\api\controller\v1;

use app\api\model\Theme as ThemeModel;
use app\api\validate\IDCollection;
use app\api\validate\IDMustBePositiveInt;
use app\lib\exception\ThemeException;

class Theme
{
//    url theme?ids=1,2,3
    public function getSimpleList($ids = '')
    {
        (new IDCollection())->goCheck();
        $ids = explode(',', $ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);
//        数据集
        if ($result->isEmpty()) {
            throw new ThemeException();
        }
        return $result;
    }
//      url theme/1
    public function getComplexOne($id)
    {
        (new IDMustBePositiveInt())->goCheck();
        $result = ThemeModel::getThemeWithProducts($id);
//        数组
        if (!$result) {
            throw new ThemeException();
        }
        return $result;
    }
}